import http from '@/utils/axios'

export default {
  searchTree(name) {
    return http({
      url: `/management-authority/role/roles/tree?searchName=${name}`,
      method: 'get',
    })
  },
  getTree(parentId) {
    return http({
      url: `/management-authority/role/roles/page/get?parent=${parentId}`,
      method: 'post',
    })
  },
  getTableData(prams) {
    let ur = ''
    if (prams.app) {
      ur += '&app=' + prams.app
    }
    if (prams.key) {
      ur += '&key=' + prams.key
    }
    if (prams.name) {
      ur += '&name=' + prams.name
    }
    return http({
      url:
        `/management-authority/role/roles/page/get?pageNo=${prams.pageNo}&pageSize=${prams.pageSize}&parent=${prams.parentId}` +
        ur,
      method: 'get',
    })
  },
  //获得所属应用选项
  getAppTypeList() {
    return http({
      url: `/management-application/app/getDoMain`,
      method: 'get',
    })
  },
  create(prams) {
    return http({
      url: `/management-authority/role/role/add`,
      method: 'post',
      data: prams,
    })
  },
  update(prams) {
    return http({
      url: `/management-authority/role/role/edit`,
      method: 'post',
      data: prams,
    })
  },
  delete(prams) {
    return http({
      url: `/management-authority/role/role/remove?id=${prams.id}`,
      method: 'post',
      data: prams,
    })
  },
  /**=关联人员===========
   * */
  //表格数据
  getPersonnel(prams) {
    return http({
      url: `/management-authority/role/user/bound`,
      method: 'get',
      params: prams,
    })
  },
  //人员待绑定
  getUserToBound(prams) {
    return http({
      url: `/management-authority/role/user/to_bound`,
      method: 'get',
      params: prams,
    })
  },
  //人员已绑定
  getUserBound(prams) {
    return http({
      url: `/management-authority/role/user/bound`,
      method: 'get',
      params: prams,
    })
  },
  //人员绑定
  getUserBind(prams) {
    return http({
      url: `/management-authority/role/user/bind`,
      method: 'post',
      data: prams,
    })
  },
  //人员解绑定
  getUserUnbind(prams) {
    return http({
      url: `/management-authority/role/user/unbind`,
      method: 'post',
      data: prams,
    })
  },

  /**==关联权限===*/
  //权限待绑定
  getPerToBound(prams) {
    return http({
      url: `/management-authority/role/privilege/to_bound`,
      method: 'get',
      params: prams,
    })
  },
  //权限组待绑定
  getPerGourpToBound(prams) {
    return http({
      url: `/management-authority/role/privilege_group/to_bound`,
      method: 'get',
      params: prams,
    })
  },
  //权限已绑定
  getPerBound(prams) {
    return http({
      url: `/management-authority/role/privilege/bound`,
      method: 'get',
      params: prams,
    })
  },
  //权限绑定
  getPerBind(prams) {
    return http({
      url: `/management-authority/role/privilege/bind`,
      method: 'post',
      data: prams,
    })
  },
  //权限解绑定
  getPerUnbind(prams) {
    return http({
      url: `/management-authority/role/privilege/unbind`,
      method: 'post',
      data: prams,
    })
  },
}
